<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="author" content="wangbo">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>


  // 求数组的和 4中方法编写
    // 求数组的和 4中方法编写
    let arr = [78, 96, 52, 123, 214, 56, 7, 85, 26]
    let sum = 0;
    // for
    for (let i = 0; i < arr.length; i++) {
      // sum = sum+arr[i];
      sum += arr[i];
    }
    console.log(sum)
    // fin 数组的下标,对象的属性
    sum = 0;
    for (let i in arr) {
      sum += arr[i];
    }
    console.log(sum)
    //fof 数组的值
    sum = 0;
    for (let val of arr) {
      sum += val
    }
    console.log(sum)
    // 不许删除,添加数据
    sum = 0;
    // 形参有且只有一个的时候
    arr.forEach(val => sum += val)
    // arr.forEach((val) => {
    //   sum +=val
    // })
    console.log(sum)


  </script>
</body>

</html>